package vmcs.ui.interfacecontrol;

import java.awt.*;
import java.awt.event.*;

import vmcs.controller.MachineryController;
import vmcs.simulationsystem.*;
import vmcs.store.Store;

public class JavaMachineryPanelBuilder extends MachineryPanelBuilder{
	private MachinerySimulationPanel machinerySimulationPanel = null;
	public JavaMachineryPanelBuilder(ISimulatorPanel startUpPanel,
			MachineryController machineryController) {
		super(startUpPanel, machineryController);
		machinerySimulationPanel = new MachinerySimulationPanel();
	}

	@Override
	public void buildDoor() {
		this.machinerySimulationPanel.setDoorDisplay(new Checkbox());
		this.machinerySimulationPanel.getDoorDisplay().addItemListener(new DoorListener(machineryController));
		this.machinerySimulationPanel.getDoorDisplay().setLabel("Door Locked");
	}

	@Override
	public void buildCashBoxDisplay() {
		this.machinerySimulationPanel.setCashDisplay(new StoreViewer(Store.CASH, 
				machineryController.getMainController().getStoreController()));
	}

	@Override
	public void buildDrinkDisplay() {
		this.machinerySimulationPanel.setDrinksDisplay(new StoreViewer(Store.DRINK, 
				machineryController.getMainController().getStoreController()));
	}

	@Override
	public void buildMachineryPanel() {
        String TITLE = "Machinery Panel";
		this.machinerySimulationPanel.setDialog(new Dialog(((SimulatorControlPanel)this.startUpPanel).getFrame(), TITLE, false));


        Label lb = new Label(TITLE);
        lb.setFont(new Font("Helvetica", Font.BOLD, 24));
        lb.setAlignment(Label.CENTER);


        Panel dp = new Panel();        
        dp.add(this.machinerySimulationPanel.getDoorDisplay());
        
        Panel tp = new Panel();
        tp.setLayout(new GridLayout(0, 1));
        tp.add(this.machinerySimulationPanel.getCashDisplay());
        tp.add(this.machinerySimulationPanel.getDrinksDisplay());

        this.machinerySimulationPanel.getDialog().setLayout(new BorderLayout());
        this.machinerySimulationPanel.getDialog().add("North", lb);
        this.machinerySimulationPanel.getDialog().add("Center", tp);
        this.machinerySimulationPanel.getDialog().add("South", dp);
        this.machinerySimulationPanel.getDialog().pack();

        this.machinerySimulationPanel.getDialog().addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent e) {
                	machineryController.closeMachineryPanel();
                }
        });
	}
	
	@Override
	public IMachineryPanel getMachineryPanel() {
		return machinerySimulationPanel;
	}

}
